// index.js
const defaultAvatarUrl = 'https://mmbiz.qpic.cn/mmbiz/icTdbqWNOwNRna42FI242Lcia07jQodd2FJGIYQfG0LAJGFxM4FbnQP6yfMxBgJ0F3YRqJCJ1aPAK2dQagdusBZg/0'

Component({
  data: {
    motto: 'Hello World',
    userInfo: {
      avatarUrl: defaultAvatarUrl,
      nickName: '',
    },
    hasUserInfo: false,
    canIUseGetUserProfile: wx.canIUse('getUserProfile'),
    canIUseNicknameComp: wx.canIUse('input.type.nickname'),
    like123456:[
      {
        id:1,
        name:'1',
        current:false,
        prev:true,
        isNext:false
      },
      {
        id:2,
        name:'2',
        current:false,
        prev:true,
        isNext:false
      },
      {
        id:3,
        name:'3',
        current:false,
        prev:true,
        isNext:false
      },
      {
        id:4,
        name:'4',
        current:false,
        prev:true,
        isNext:false
      },
      {
        id:5,
        name:'5',
        current:true,
        prev:false,
        isNext:false
      },
      {
        id:6,
        name:'6',
        current:false,
        prev:false,
        isNext:true
      },
      {
        id:7,
        name:'喜',
        current:false,
        prev:false,
        isNext:true
      },
      {
        id:8,
        name:'',
        current:false,
        prev:false,
        isNext:true
      }
    ],
    like123456ProgressIndex:4
  },
  onShow() {

    if (typeof this.getTabBar === 'function' &&
    this.getTabBar()) {
      this.getTabBar().setData({
        selected: 0
      })
    }
    
  },
  methods: {
    // 事件处理函数
    pickUpInStore() {
      console.log("pickUpInStore");
      wx.switchTab({
        url: '/pages/order/meal'
      })
    },
    isShowProgress(index){
      var current_index=0;
      for(var i in this.like123456){
          if(this.like123456[i].current){
            if(index==(i-1)){
                return true;
            }
          }
      }
      return false;
    },
    getCurrentIndex(){
      for(var i in this.like123456){
        if(this.like123456[i].current){
          console.log("当前like进度index",i);
          return parseInt(i);
        }
    }
    },
    onChooseAvatar(e) {
      const { avatarUrl } = e.detail
      const { nickName } = this.data.userInfo
      this.setData({
        "userInfo.avatarUrl": avatarUrl,
        hasUserInfo: nickName && avatarUrl && avatarUrl !== defaultAvatarUrl,
      })
    },
    onInputChange(e) {
      const nickName = e.detail.value
      const { avatarUrl } = this.data.userInfo
      this.setData({
        "userInfo.nickName": nickName,
        hasUserInfo: nickName && avatarUrl && avatarUrl !== defaultAvatarUrl,
      })
    },
    getUserProfile(e) {
      // 推荐使用wx.getUserProfile获取用户信息，开发者每次通过该接口获取用户个人信息均需用户确认，开发者妥善保管用户快速填写的头像昵称，避免重复弹窗
      wx.getUserProfile({
        desc: '展示用户信息', // 声明获取用户个人信息后的用途，后续会展示在弹窗中，请谨慎填写
        success: (res) => {
          console.log(res)
          this.setData({
            userInfo: res.userInfo,
            hasUserInfo: true
          })
        }
      })
    },
  },
})
